<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<!--Converted with LaTeX2HTML 98.1 release (February 19th, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->


<title>Carmichael Numbers</title>
<meta name="description" content="Problem G: Carmichael Numbers">
<meta name="keywords" content="htmlatex">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head><body bgcolor="#ffffff" lang="EN">

<h1><br clear="ALL"><center><table bgcolor="#0060f0"><tbody><tr><td><b><font color="#c0ffff" size="5">&nbsp;<a name="SECTION0001000000000000000000">
Carmichael Numbers</a>&nbsp;</font></b></td></tr></tbody></table></center>
</h1>
An important topic nowadays in computer science is cryptography. Some people even 
think
that cryptography is the only important field in computer science, and that
life would not matter at all without cryptography.

Alvaro is one of such persons, and is designing a set of cryptographic
procedures for cooking paella. Some of the cryptographic algorithms he is
implementing make use of big prime numbers. However, checking if a big number
is prime is not so easy. An exhaustive approach can require the division of
the number by all the prime numbers smaller or equal than its square root. For
big numbers, the amount of time and storage needed for such operations would
certainly ruin the paella. 

<p>
However, some probabilistic tests exist that offer
high confidence at low cost. One of them is the Fermat test.

</p><p>
Let <i>a</i> be a random number between 2 and <i>n</i> - 1 (being <i>n</i> the number whose
primality we are testing). Then, <i>n</i> is probably prime if the following
equation holds: 
<br></p><p></p>
<div align="CENTER">
<!-- MATH: \begin{displaymath}
a^n \bmod n = a
\end{displaymath} -->


<img src="acm-10006_files/10006img1.gif" alt="\begin{displaymath}a^n \bmod n = a
\end{displaymath}" height="27" width="104">
</div>
<br clear="ALL">
<p></p>
If a number passes the Fermat test several times then it is prime with a high 
probability.

<p>
Unfortunately, there are bad news. Some numbers that are not prime still pass
the Fermat test with every number smaller than themselves. These numbers are
called Carmichael numbers.

</p><p>
In this problem you are asked to write a program to test if a given number is
a Carmichael number. Hopefully, the teams that fulfill the task will one day be
able to taste a delicious portion of encrypted paella. As a side note, we need
to mention that, according to Alvaro, the
main advantage of encrypted paella over conventional paella is that nobody but you 
knows
what you are eating.

</p><p>

</p><h2><font color="#0070e8"><a name="SECTION0001001000000000000000">
Input</a>&nbsp;</font>
</h2>
The input will consist of a series of lines, each
containing a small positive number <i>n</i> (
<!-- MATH: $2 < n < 65000$ -->
2 &lt; <i>n</i> &lt; 65000). A number <i>n</i> = 0 will
mark the end of the input, and must not be processed. 

<p>

</p><h2><font color="#0070e8"><a name="SECTION0001002000000000000000">
Output</a>&nbsp;</font>
</h2> 
For each number in the
input, you have to print if it is a Carmichael number or not, as shown in the
sample output. 

<p>

</p><h2><font color="#0070e8"><a name="SECTION0001003000000000000000">
Sample Input</a>&nbsp;</font>
</h2>
<pre>1729
17
561
1109
431
0
</pre>

<p>

</p><h2><font color="#0070e8"><a name="SECTION0001004000000000000000">
Sample Output</a>&nbsp;</font>
</h2>
<pre>The number 1729 is a Carmichael number.
17 is normal.
The number 561 is a Carmichael number.
1109 is normal.
431 is normal.
</pre>

<p>

</p><p>
<br></p><hr>
<address>
<i>Miguel Revilla</i>
<br><i>2000-08-21</i>
</address>
</body></html>